package com.yqh.controller;

import com.yqh.Result;
import com.yqh.dto.UserDTO;
import com.yqh.entity.User;
import com.yqh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 用户模块功能
 *
 * @author 阳秋豪
 * @createTime 2024/3/22
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     *
     * @param user 用户及密码
     */
    @PostMapping("/login")
    public Result login( @RequestBody UserDTO userDTO) {
        return Result.success(userService.login(userDTO));
    }

    /**
     * 注册
     *
     * @param user 用户及密码
     */
    @PostMapping("/register")
    public Result register(@RequestBody User user) {
        userService.register(user);
        return Result.success();
    }
}
